package com.zx.ishopping.mapper;

import com.zx.ishopping.VO.OrderItemsVo;
import com.zx.ishopping.entity.OrderItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderItemsMapper {


    /**
     * 根据id删除订单中的内容
     * @param id
     */
    @Delete("delete from order_items where id = #{id}")
    void deleteOrderItems(Long id);


    /**
     * 根据订单id查询订单中的内容
     * @param orderId
     * @return
     */
    @Select("select order_items.*,products.name as productName,products.price from order_items inner join products on order_items.product_id = products.id where order_id = #{orderId}")
    List<OrderItemsVo> getOrderItemsList(Long orderId);

    /**
     * 根据id查询订单中的内容
     * @param id
     * @return
     */
    @Select("select * from order_items where id = #{id}")
    OrderItem getProduct(Long id);

    /**
     * 修改订单中的内容
     * @param orderItem
     */
    @Update("update order_items set quantity = #{quantity},total_price = #{totalPrice} where id = #{id}")
    void updateOrderItem(OrderItem orderItem);

    /**
     * 添加订单中的内容
     * @param orderItems
     */
    @Insert("insert into order_items(order_id,product_id,quantity,total_price) values(#{orderId},#{productId},#{quantity},#{totalPrice})")
    void addOrderItems(OrderItem orderItems);
}
